{extend name="template/base" /}
{block name="content"}
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select name="pid">
                <option value="0"></option>
                {foreach $menuList as $vo}
                <option value="{$vo.id}" {if condition="$menu_info['l']-1 eq $vo.r" }selected="selected" {/if} >{$vo.line}{$vo.title}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-inline">
            <input type="text" name="menuName" lay-verify="required" value="{$menu_info.title}" placeholder="请输入菜单名称"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单链接</label>
        <div class="layui-input-inline">
            <input type="text" name="url" value="{$menu_info.url}" {if condition="$menu_info['pid'] eq 1" }lay-verify="required" {/if} placeholder="请输入菜单链接" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"><模块名/控制器/操作方法></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-inline">
            <input type="text" name="menuIcon" value="{$menu_info.icon}" {if condition="$menu_info['pid']  eq 1"
                   }lay-verify="required" {/if} placeholder="请输入菜单图标" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">具体参考layui官网</div>
    </div>
    <input type="hidden" name="id" value="{$menu_info.id}">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="editMenu">立即提交</button>
        </div>
    </div>
</form>
{/block}
{block name="script" }
<script>
    layui.use('form', function () {
        var form = layui.form,
            $ = layui.jquery;
        //监听提交
        form.on('submit(editMenu)', function (data) {
            var userInfo = data.field;
            var url = "{:url('Menu/editMenu')}";
            $.post(url, userInfo, function (data) {
                if (data.status == 'error') {
                    layer.msg(data.msg, {icon: 5});//失败的表情
                    return;
                } else if (data.status == 'success') {
                    layer.msg(data.msg, {
                        icon: 6,//成功的表情
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.reload();
                    });
                }
            })

            return false;//阻止表单跳转
        });
    });
</script>
{/block}
